package com.imachen.ymcc.mq.producer;

import com.imachen.ymcc.domain.MediaFile;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;
/**
 * @description: 媒体服务生产者
 * @author: AChen
 * @date: 2022/10/11 0011 : 18:07
 * @version: ver1.0
 * @email
 */
@Component
public class CourseVideoPushProducer {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    public Boolean sendMessage(MediaFile mediaFile){
        // 1.创建一个message对象，将参数交给他
        Message<MediaFile> message = MessageBuilder.withPayload(mediaFile).build();
        // 2.发送同步消息，得到返回值
        SendResult sendResult = rocketMQTemplate.syncSend("topic-course-video:tag-push", message);
        SendStatus sendStatus = sendResult.getSendStatus();
        // 3.返回消息是否发送成功
        return sendStatus.equals(SendStatus.SEND_OK)?true:false;
    }

}
